import sys
sys.path.append("..")
from database.db_handler import MysqlHander
from common.my_http import MyHttp
import urllib.request
from bs4 import BeautifulSoup
from common.entity_data import EntityData
import glob
import jieba
import re
import threading
import hashlib

'''
品牌
'''

class ZhongguogongchengyuanYuanshiData:
    def __init__(self):
        self.entity = EntityData()
        self.url_map = {}
        pass
    
    def get_data(self):
        url = "https://www.cae.cn/cae/html/main/col48/column_48_1.html"
        bs4_data = MyHttp.bs4_utf8_data(url)
        divs = bs4_data.find_all(name="div", attrs={'class':'ysxx_namelist'})
        name_set = ""
        for div in divs:
            for d in div.find_all("a"):
                name_set += "|" + d.text.split("(")[0]

        print("中国工程院院士:" + name_set)
        self.entity.add_entity_data("中国工程院院士", "", 200, 2000005, "中国工程院", "", name_set)
        self.entity.update_entity_data("中国工程院院士", "", 200, 2000005, "中国工程院", "", name_set)

    def get_data2(self):
        url = "https://www.cae.cn/cae/html/main/col50/column_50_1.html"
        bs4_data = MyHttp.bs4_utf8_data(url)
        name_set = ""
        for d in bs4_data.find(name="div", attrs={'class':'ysxx_name_tab'}).find_all("a"):
            name_set += "|" + d.text.split("(")[0]

        print("中国工程院院士:" + name_set)
        self.entity.add_entity_data("中国工程院外籍院士", "", 200, 2000005, "中国工程院", "", name_set)
        self.entity.update_entity_data("中国工程院外籍院士", "", 200, 2000005, "中国工程院", "", name_set)



def zhongguogongchengyuan_yuanshi_api():
    d = ZhongguogongchengyuanYuanshiData()
    d.get_data()
    d.get_data2()

if __name__ == '__main__':
    zhongguogongchengyuan_yuanshi_api()
